package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.IntegralType;
import cn.wolfcode.trip.base.query.IntegralTypeQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IIntegralTypeService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：积分类型控制器
 *
 * @package: cn.wolfcode.trip.admin.controller
 * @author: Patch
 * @date: 2019/5/30 14:06
 * 总结:
 */
@Controller
@RequestMapping("integralType")
public class IntegralTypeController {
    @Autowired
    private IIntegralTypeService typeService;

    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") IntegralTypeQueryObject qo) {
        // 设置根据创建时间排序
        qo.setOrderBy("inputTime desc");
        model.addAttribute("pageInfo", typeService.query(qo));
        return "integral/type/list";
    }

    /**
     * 保存和更新
     *
     * @param type
     * @return
     */
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(IntegralType type) {
        JsonResult result = new JsonResult();
        try {
            typeService.saveOrUpdate(type);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark("亲，操作失败");
        }
        return result;
    }

}
